package cn.wolfcode.luowowo.scenic.service.impl;


import cn.wolfcode.luowowo.scenic.domain.Ticket;
import cn.wolfcode.luowowo.scenic.mapper.TicketDetailMapper;
import cn.wolfcode.luowowo.scenic.mapper.TicketMapper;
import cn.wolfcode.luowowo.scenic.service.ITicketService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class TicketServiceImpl implements ITicketService {

    @Autowired
    private TicketDetailMapper ticketDetailMapper;
    @Autowired
    private TicketMapper ticketMapper;

    @Override
    public List<Ticket> listByDestIdAndThemeId(Long destId, Long themeId) {
        List<Ticket> tickets = ticketMapper.selectByDestIdAndThemeId(destId,themeId);
        for (Ticket ticket : tickets) {
            Integer minPrice = ticketDetailMapper.selectMinPriceByTicketId(ticket.getId());
            ticket.setPrice(minPrice);
        }
        return tickets;
    }

    @Override
    public Ticket getById(Long tid) {
        Ticket ticket = ticketMapper.selectByPrimaryKey(tid);
        ticket.setPrice(ticketDetailMapper.selectMinPriceByTicketId(ticket.getId()));
        return ticket;
    }

    @Override
    public List<Ticket> listHotTicketTop4() {
        List<Ticket> tickets = ticketMapper.selectHotTicketTop4();
        for (Ticket ticket : tickets) {
            Integer minPrice = ticketDetailMapper.selectMinPriceByTicketId(ticket.getId());
            ticket.setPrice(minPrice);
        }
        return tickets;
    }

}
